package dom.xpath.query;

import dom.xpath.util.Token;
import dom.xpath.util.TokenBuilder;

/**
 * This class indicates exceptions during query parsing.
 * 
 * @author Workgroup DBIS, University of Konstanz 2005-07, ISC License
 * @author Tim Petrowsky
 */
public final class ParseException extends QueryException  {

	private static final long serialVersionUID = -2270250227533072044L;

	/**
	 * Constructor.
	 * @param message thrown message
	 */
	public ParseException(final String message) {
		super(message);
	}
	
	/**
	 * Constructor.
	 * 
	 * @param s
	 *            message in detail
	 * @param e
	 *            message extension
	 */
	public ParseException(final String s, final Object... e) {
		super(info(s, e));
	}
	
   /**
	 * Global method, replacing all % characters (see
	 * {@link #inf(String, Object...)}.
	 * 
	 * @param string
	 *            string to be extended
	 * @param ext
	 *            text text extensions
	 * @return extended string
	 */
	public static String info(final String string, final Object... ext) {
		return Token.string(inf(string, ext));
	}
	
	/**
	 * Global method, replacing all % characters in the input string by the
	 * specified extension objects, which can be byte arrays or any other object
	 * that can be cast to string.
	 * 
	 * @param string
	 *            string to be extended
	 * @param ext
	 *            text text extensions
	 * @return token
	 */
	public static byte[] inf(final String string, final Object... ext) {
		final TokenBuilder info = new TokenBuilder();
		info.add(string, ext);
		return info.finish();
	}

}
